package main

import (
	"fmt"
	"log"
	"ipdatacloud/find"
)

func test1() {
	//查询IPv4归属地
	// 1.创建查询实例
	locationSearch, err := find.GetObjectV4LocationMemory("ipdatacloud_city.dat")
	if err != nil {
		log.Println("创建查询实例错误：", err.Error())
		return
	}

	//2.查询ip地址
	locationStr, _ := locationSearch.Get("::ffff:180.124.68.28")
	fmt.Println(locationStr)

	//3.解析IP地址
	location, _ := find.NewLocation(locationStr)
	fmt.Printf("%+v \n", location)

}

// test2
// @Description: 使用结构体 Access 进行ipv4，ipv6的混合查询
func test2() {
	// 1. 初始化Access结构体
	access, err := find.GetAccess("ipdatacloud_city.dat", "ipv6_city.dat")
	if err != nil {
		fmt.Println(err)
		return
	}

	// 2.查询
	res, err := access.Get("::ffff:180.124.68.28")
	if err != nil {
		fmt.Println(err)
		return
	}

	// 3.解析为对应结构体
	location, _ := find.NewLocation(res)
	fmt.Printf("%+v \n", location)

}
